/**
 * @ 从一个字符串里删除一个字符或一个字符串
 * @ 怎样删除一个字符串
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @startpackage	default
 * @TODO how to handle negative start, or count that exceeds strlen
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// 函数声明
char *removeString(const char source[], int start, int count);

// 主函数
int main(void) {
	const char source[] = {"abcdefghijklmnopqrstuvwxyz"};
	int start, count;
	
	// 输入
	printf("\n母字符串：%s\n\n", source);
	printf("请输入要删除的字符串的开始下标：");
	scanf("%d", &start);
	printf("请输入要删除的字符串的个数：");
	scanf("%d", &count);

	// 调用函数
	printf("%s\n", removeString(source, start, count));

	return 0;
}

// 删除字符串
char *removeString(const char source[], int start, int count) {
	int length = strlen(source);
	char *result = malloc(sizeof(char) * (length - count + 1));
	
	int i = 0;
	int j = 0;
	for (i = 0; i < length; i++) {
		if (i < start || i > (start + count)) {
			result[j++] = source[i];
		}
	}

	return result;
 
}
